package com.hsl.study.aspect;

import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Author: hsl
 * @CreateTime: 2025-02-14  20:23
 * 新建一个切面类 三个注解是标配
 * @Pointcut 往哪切
 * 业务落地切面成
 */
@Aspect
@Component
@Slf4j
public class DemoAspect{

    /**
     * 所有带RestController的 且在com.hsl.study 并且排除 public 的
     */
    @Pointcut("(@target(org.springframework.web.bind.annotation.RestController)) " +
            "&& within(com.hsl.study..*) && execution(public * *(..))")

    public void pointcut(){}
    @Around(value = "pointcut()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
        log.info("======AOP 进入=======");
        //主业务逻辑 放行
        Object proceed = proceedingJoinPoint.proceed();
        log.info("======AOP 退出=======");
        return proceed;
    }
}
